<template>
  <div>
    <div style="padding: 10px">
      <el-row>
        <el-col span="6">
          题目：
          <el-input v-model="text" @keyup.enter.native="load" style="width: 70%"> 
            <i slot="prefix" class="el-input__icon el-icon-search"></i>
          </el-input>
        </el-col>
       
        <el-col span="2">
          <el-button  type="primary" size="mini" >查找</el-button>
        </el-col>
        <el-col span="2">
          <el-button @click="add" type="primary" size="mini" >新增</el-button>
        </el-col>
      </el-row>
     
    </div>
    <el-table :data="tableData" border stripe style="width: 100%">
      <el-table-column prop="id" label="ID" width="100" sortable> </el-table-column>
      <el-table-column prop="A" label="题目"></el-table-column>
      <el-table-column prop="B" label="重点"></el-table-column>
      <el-table-column prop="C" label="难点"></el-table-column>
      <el-table-column
          fixed="right"
          label="操作"
          width="200">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" circle @click="edit(scope.row)"></el-button>
          <el-popconfirm
              @confirm="del(scope.row.id)"
              title="确定删除？"
          >
            <el-button type="danger" icon="el-icon-delete" circle slot="reference"
                       style="margin-left: 10px"></el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin-top: 10px">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-size="pageSize"
        :page-sizes="[2, 5, 10]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>

    <!-- 弹窗   -->
    <el-dialog title="信息" :visible.sync="dialogFormVisible" width="30%"
               :close-on-click-modal="false">
      <el-form :model="entity">
        <el-form-item label="题目" label-width="150px">
          <el-input v-model="entity.name" autocomplete="off" style="width: 80%"></el-input>
        </el-form-item>
        <el-form-item label="重点" label-width="150px">
          <el-input v-model="entity.no" autocomplete="off" style="width: 80%"></el-input>
        </el-form-item>
        <el-form-item label="难点" label-width="150px">
          <el-input v-model="entity.no1" autocomplete="off" style="width: 80%"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="save">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import API from '../../utils/request'
const url = "/api/category/"

export default {
  name: "Category",
  data() {
    return {
      fileList: [],
      options: [],
      text: '',
      user: {},
      tableData: [],
      pageNum: 1,
      pageSize: 10,
      entity: {},
      total: 0,
      dialogFormVisible: false
    };
  },
  created() {
    this.user = sessionStorage.getItem("user") ? JSON.parse(sessionStorage.getItem("user")) : {}
    this.$emit('user', this.user);
    this.load()
  },
  methods: {
    fileSuccessUpload(res) {
      this.entity.file = "http://localhost:9999/files/" + res.data;
      this.fileList = [res.data]
      console.log(res)
    },
    handleSizeChange(pageSize) {
      this.pageSize = pageSize
      this.load()
    },
    handleCurrentChange(pageNum) {
      this.pageNum = pageNum
      this.load()
    },
    load() {
      //  API.get(url + "/page", {
      //     params: {
      //       pageNum: this.pageNum,
      //       pageSize: this.pageSize,
      //       name: this.text
      //     }
      //  }).then(res => {
      //     this.tableData = res.data.records || []
      //     this.total = res.data.total
      //  })
      this.tableData =[
        {
          id:1,
          A:'测试题目',
          B:'重点',
          C:'难点',
          D:'C',
          E:'D',
          F:'A',
        },
        {
          id:1,
          A:'测试题目',
          B:'重点',
          C:'难点',
          D:'C',
          E:'D',
          F:'A',
        },
      ]
    },
    add() {
      this.entity = {}
      this.fileList = []
      this.dialogFormVisible = true
    },
    edit(obj) {
      this.entity = JSON.parse(JSON.stringify(obj))
      this.fileList = []
      this.dialogFormVisible = true
    },
    save() {

      this.$message({
               type: "success",
               message: "操作成功"
             })
             this.dialogFormVisible = false
      // if (!this.entity.id) {
      //   API.post(url, this.entity).then(res => {
      //      if (res.code === '0') {
      //        this.$message({
      //          type: "success",
      //          message: "操作成功"
      //        })
      //      } else {
      //        this.$message({
      //          type: "error",
      //          message: res.msg
      //        })
      //      }
      //      this.load()
      //      this.dialogFormVisible = false
      //   })
      // } else {
      //   API.put(url, this.entity).then(res => {
      //     if (res.code === '0') {
      //       this.$message({
      //         type: "success",
      //         message: "操作成功"
      //       })
      //     } else {
      //       this.$message({
      //         type: "error",
      //         message: res.msg
      //       })
      //     }
      //     this.load()
      //     this.dialogFormVisible = false
      //   })
      // }
    },
    del(id) {
      this.$message({
          type: "success",
          message: "操作成功"
        })
      // API.delete(url + id).then(res => {
      //   this.$message({
      //     type: "success",
      //     message: "操作成功"
      //   })
      //   this.load()
      // })
    }
  },
};
</script>

<style scoped>
</style>
